from django.template import Library

from projects.models import Aim, Deliverable, Objective, Task
from projects import utils

register = Library()

@register.inclusion_tag("aim_table.html")
def list_aims(aims):
  return {'aim_list': aims}

@register.inclusion_tag("objective_table.html")
def list_aim_objectives(aim):
  list = aim.objective_set.all()
  return {'objective_list': list}

@register.inclusion_tag("rating.html")
def aim_status(aim):
  assert isinstance(aim, Aim)
  incomplete_tasks = Task.objects.filter(deliverable__objective__aim__id = aim.id, completed_date = None)
  incomplete_deliverables = Deliverable.objects.filter(objective__aim__id = aim.id, completed_date = None)
  objectives = Objective.objects.filter(aim__id = aim.id)
  return utils.get_ratings("aim", incomplete_tasks, incomplete_deliverables, objectives)
